// Flutter imports:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

// Package imports:
import 'package:date_format/date_format.dart';
import 'package:get/get.dart';

// Project imports:
import 'package:palmf_hid/common/entities/data_base/my_database.dart';
import 'package:palmf_hid/common/values/values.dart';

import 'data_back_dialog.dart';

///历史数据列表项
Widget historyItem(
    {required Results item,
    required int index,
    required Function onDelete,
    required Function onPrint}) {
  String sampleType = 'unknown'.tr;
  switch (item.sample) {
    case 1:
      sampleType = 'wholeBlood'.tr;
      break;
    case 2:
      sampleType = 'serum'.tr;
      break;
    case 3:
      sampleType = 'other'.tr;
      break;
  }
  String resultAfterHandle = item.result.toString();
  double resultD = double.parse(resultAfterHandle);
  if (resultD < 0) {
    resultD = 0;
  }
  String result = resultD.toStringAsFixed(item.saveNum).toString();
  String resultDisplay = item.resultDisplay.toString();
  if (resultDisplay.contains("<") || resultDisplay.contains(">")) {
    result = '$resultDisplay$result';
  } else if (resultDisplay.contains("↑") || resultDisplay.contains("↓")) {
    result = '$result$resultDisplay';
  }
  return Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text('${index + 1}.'),
          Text('HP${item.deviceNo == "" ? "000000000000" : item.deviceNo}',
              style: _TextStyle())
        ],
      ),
      // Text('UP:${result.referUpper} L:${result.referLower} S:${result.saveNum}',
      //     style: _TextStyle()),

      const SizedBox(
        height: 5,
      ),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          Expanded(
              flex: 3,
              child: Text(
                  '${'project'.tr}:${item.projectName.replaceAll(" ", "").replaceAll("\u0000", "")}',
                  style: _TextStyle())),
          Expanded(
              flex: 4,
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Expanded(
                        child: Text('${'type'.tr}:$sampleType',
                            style: _TextStyle())),
                    Text('${'number'.tr}:${item.patientId}',
                        style: _TextStyle())
                  ]))
        ],
      ),
      const SizedBox(
        height: 5,
      ),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          Expanded(
              flex: 3,
              child: Text('${'result'.tr}:$result', style: _TextStyle())),
          Expanded(
              flex: 4,
              child: Text('${'unit'.tr}:${item.resultUnit ?? ""}',
                  style: _TextStyle())),
        ],
      ),
      const SizedBox(
        height: 5,
      ),
      Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Text(
            '${'synchronizeOrTestTime'.tr}：${formatDate(item.time, [
                  yyyy,
                  '-',
                  mm,
                  '-',
                  dd,
                  " ",
                  HH,
                  ':',
                  nn,
                  ':',
                  ss
                ])}',
            style: const TextStyle(color: Colors.grey, fontSize: 14),
          )
        ],
      ),
      const SizedBox(
        height: 10,
      ),
      Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          // Container(
          //     padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
          //     decoration: BoxDecoration(
          //         borderRadius: BorderRadius.circular(5), color: Colors.green),
          //     child: InkWell(
          //       onTap: () {
          //         onPrint(item);
          //       },
          //       child: Text(
          //         "print".tr,
          //         style:
          //             const TextStyle(color: MyColor.c_FFFFFFFF, fontSize: 12),
          //       ),
          //     )),
          // const SizedBox(
          //   width: 10,
          // ),
          Container(
              padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5),
                  color: Colors.red.shade300),
              child: InkWell(
                onTap: () {
                  showDialog(
                      context: Get.context!,
                      builder: (ctx) {
                        return buildDataBackDialog(
                            str: "deleteHistoryNotice".tr,
                            onPress: () {
                              onDelete(item);
                            });
                      });
                },
                child: Text(
                  "delete".tr,
                  style:
                      const TextStyle(color: MyColor.c_FFFFFFFF, fontSize: 12),
                ),
              ))
        ],
      )
    ],
  );
}

_TextStyle() {
  return const TextStyle(color: MyColor.c_99000000, fontSize: 14);
}
